package servlet;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import dao.UserInfo;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/9/21 11:40
 * @Description: 不推荐使用
 */
public class DeprecatedServlet extends HttpServlet {

  private static final ComboPooledDataSource DS = new ComboPooledDataSource();

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    // 获取内容
    String name = req.getParameter("name");
    String password = req.getParameter("password");

    // 查询数据库
    QueryRunner runner = new QueryRunner(DS);
    try {
      UserInfo user = runner.query("select * from userInfo where name = ? ",
          new BeanHandler<UserInfo>(UserInfo.class));
      if (user == null) {
        // 失败
      }

      if (user.getPassword().equals(password)) {
        // 处理
      } else {
        // 处理
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
